package exam.axhu.junit;

import static org.junit.Assert.*;

import java.util.List;

import exam.axhu.entity.Judge;
import exam.axhu.service.JudgeService;

import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class JudgeTest {
	private static JudgeService judgeService;
	
	@BeforeClass
	public static void setUpBeforeClass() throws Exception{
		try {
			ApplicationContext act = new ClassPathXmlApplicationContext("beans.xml");
			judgeService =(JudgeService) act.getBean("judgeServiceImpl");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	@Test
	public void save() {
		if(judgeService.save(new Judge("1+2=?","2","4","B"))==1)
			System.out.println("already have!");
	
	}
	
	@Test
	public void delete() {
		judgeService.delete(1);
	
	}
	
	@Test
	public void update() {
		Judge judge = judgeService.findByID(1);
		judge.setJudgeAnswer("A");
		judgeService.update(judge);
	
	}
	
	
	
	@Test
	public void find() {
		Judge ems = judgeService.findByID(1);
		/*if(ems==null) System.out.println("NO");
		else*/
			System.out.println(ems.getJudgeID());
	}
	
	
	@Test
	public void list() {
	
		List<Judge> ems = judgeService.list();
		for(Judge em:ems){
			System.out.println(em.getJudgeID());
		}
				
	}

}
